import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { OrdersVO, OrdersForm, OrdersQuery } from '@/api/goods/order/types';

/**
 * 查询订单列表
 * @param query
 * @returns {*}
 */

export const listOrders = (query?: OrdersQuery): AxiosPromise<OrdersVO[]> => {
  return request({
    url: '/order/orders/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询订单详细
 * @param id
 */
export const getOrders = (id: string | number): AxiosPromise<OrdersVO> => {
  return request({
    url: '/order/orders/' + id,
    method: 'get'
  });
};

/**
 * 查询订单详细
 */
export const getOrderStateList = (): AxiosPromise<OrdersVO> => {
  return request({
    url: '/order/orders/orderStateList',
    method: 'get'
  });
};
/**
 * 查询订单详细
 */
export const getPrintList = (query): AxiosPromise<OrdersVO> => {
  return request({
    url: '/order/orders/printList',
    method: 'get',
    params: query
  });
};
/**
 * 查询订单详细
 */
export const getOrdersAllList = (): AxiosPromise<OrdersVO> => {
  return request({
    url: '/order/orders/allList',
    method: 'get'
  });
};
/**
 * 查询订单详细
 */
export const getOrdersSetting = (): AxiosPromise<OrdersVO> => {
  return request({
    url: '/order/orderSetting/list',
    method: 'get'
  });
};
/**
 * 获取解密token
 * @param storeId 店铺id
 */
export const getOrdersAccessToken = (storeId): AxiosPromise<OrdersVO> => {
  return request({
    url: '/order/doudian/getAccessToken/' + storeId,
    method: 'get'
  });
};

/**
 * 新增订单
 * @param data
 */
export const addOrders = (data: OrdersForm) => {
  return request({
    url: '/order/orders',
    method: 'post',
    data: data
  });
};
/**
 * 新增订单
 * @param data
 */
export const updatePrintStatus = (ids: String) => {
  return request({
    url: `/order/orders/updatePrintStatus/${ids}`,
    method: 'post'
  });
};

/**
 * 新增订单
 * @param data
 */
export const customAdddictLabel = (data: any) => {
  return request({
    url: '/system/dict/data/customAdd',
    method: 'post',
    data: data
  });
};

/**
 * 修改订单
 * @param data
 */
export const updateOrders = (data: OrdersForm) => {
  return request({
    url: '/order/orders',
    method: 'put',
    data: data
  });
};

/**
 * 删除订单
 * @param id
 */
export const delOrders = (id: string | number | Array<string | number>) => {
  return request({
    url: '/order/orders/' + id,
    method: 'delete'
  });
};

/**
 * 状态修改
 * @param ordersId 客户端id
 * @param status 状态
 */
export function changeStatus(ordersId: string, status: string) {
  const data = {
    ordersId,
    status
  };
  return request({
    url: '/order/orders/changeStatus',
    method: 'put',
    data: data
  });
}

export default {
  list: listOrders,
  get: getOrders,
  add: addOrders,
  update: updateOrders,
  del: delOrders,
  getOrdersAllList: getOrdersAllList,
  getOrdersSetting: getOrdersSetting,
}